<div class="row">
<div class="col-xs-12">
<form action="<?php echo DOMAIN_ADMIN?>/navigation/add" method="post"  id='add_user_submit'>
	<table id="inputs-table" class="table table-striped table-bordered table-hover" >
		<tr>

			<td width="100" align="right"><nobr>
					<strong class="red">*</strong> 导航名称：
				</nobr></td>
			<td>
				<input type="text" name="name" id="data-role-name"
					   value="<?php echo set_value('name')?>" style="width: 300px;" maxlength="20">
				<span class="red" id="data-role-name-error" style="display: inline"><?php echo form_error('name')?></span>
			</td>
		</tr>

		<tr>

			<td width="100" align="right"><nobr>
					 链接地址：
				</nobr></td>
			<td>
				<input type="text" name="link" id="data-role-link"
					   value="<?php echo set_value('name')?>" style="width: 300px"  >
				<span class="red" id="data-role-link-error"  style="display: inline"><?php echo form_error('link')?></span>
			</td>
		</tr>

		<tr>

			<td width="100" align="right"><nobr>
					<strong class="red">*</strong>父级操作：
				</nobr></td>
			<td>
				<select name="pid">
					<option value="0">顶级</option>
					<?php if(!empty($top_permissions)) {?>
					<?php foreach($top_permissions as $val){ ?>
						<option value="<?php echo $val['id']?>"><?php echo $val["name"]?></option>
					<?php }  }?>

				</select>
			</td>
		</tr>


		<tr>

			<td width="100" align="right"><nobr>
					<strong class="red"></strong> 排序：
				</nobr></td>
			<td>
				<input type="text" name="orderby" value="<?php echo set_value('orderby')?>" style="width: 300px">

			</td>
		</tr>

		
		<tr>
			<td colspan="2" align="center">
				<button class="btn btn-info btn-sm" type="submit" >提交</button>
			</td>
		</tr>
	</table>
</form>
</div>
</div>

<script type="text/javascript">

	//ajax判断导航名称是否重复
	$(document).on('keyup', '#data-role-name', function () {
		var navigation_name=$('#data-role-name').val();
		var url='<?php echo DOMAIN_MAIN?>/api/permissions/check_navigation_name';
		var params={
			navigation_name:navigation_name
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				var new_dom='导航名称已存在，请重新填写！';
				$("#data-role-name-error").html(new_dom);
				return false;
			}else{
				$("#data-role-name-error").html('');
				return true;
			}

		},'json');

	});
	//鼠标离开用户名输入框时触发
	$(document).on('blur', '#data-role-name', function () {
        var name=$('#data-role-name').val();
		var admin_name_length=name.length;
		if(admin_name_length<1){
			$("#data-role-name-error").html('导航名称不能为空！');
			return false;
		}else{
			var url='<?php echo DOMAIN_MAIN?>/api/permissions/has_special_character';
			var params={
				name:name
			};

			$.get(url, params, function (data) {
				if(data.state=='success'){
					var new_dom='名称存在非法字符，请重新填写！';
					$("#data-role-name-error").html(new_dom);
					return false;
				}else{
					$("#data-role-name-error").html('');
					return true;
				}

			},'json')
		}

	});

	//输入时ajax判断链接是否已经存在
	$(document).on('keyup', '#data-role-link', function () {

		var link=$('#data-role-link').val();
		var url='<?php echo DOMAIN_MAIN?>/api/permissions/check_navigation_link';
		var params={
			link:link
		};

		$.get(url, params, function (data) {
			if(data.state=='success'){
				var new_dom='链接已存在，请重新填写！';
				$("#data-role-link-error").html(new_dom);
				return false;
			}else{
				$("#data-role-link-error").html('');
				return true;
			}

		},'json');

	});

</script>